/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VocSymbTest2;

//import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 *
 * @author StiggieBig
 */
public class ItemSet implements Comparable<ItemSet>, Iterable<Item>{

    SortedSet<Item> itemSet;
    
    public ItemSet() {
        itemSet = new TreeSet<Item>(new ItemComparator<Item>());
    }

    public ItemSet(Item newItem) {
        itemSet = new TreeSet<Item>(new ItemComparator<Item>());
        itemSet.add(newItem);
    }

    public ItemSet(ItemSet copyFrom) {
        itemSet = new TreeSet<Item>(new ItemComparator<Item>());
        for (Item tempItem : copyFrom) {
            itemSet.add(tempItem);
        }
    }
    
    public boolean add(Item newItem){
    	return itemSet.add(newItem);
    }
    
    public boolean addAll(ItemSet I){
    	return itemSet.addAll(I.itemSet);
    }

    public boolean isEmpty(){
    	return itemSet.isEmpty();
    }
    
    public void clear(){
    	itemSet.clear();
    }
    public void Print() {
    	System.out.print("{");
        for (Item tempItem : itemSet) {
            tempItem.Print();
            if(tempItem != itemSet.last()){
            	System.out.print(", ");
            }
        }
        System.out.print("}");
    }
    
    public int size(){
    	return itemSet.size();
    }
    
    @Override
    public int compareTo(ItemSet o) {
        int compVal = 0;
        Iterator<Item> it1 = this.iterator();
        Iterator<Item> it2 = o.iterator();
        
        if(this.size() < o.size()){
            compVal = -1;
        } else if(this.size() > o.size()){
        	compVal = 1;
        } else 	if (this.size() != 0){
            while(compVal == 0 && it1.hasNext() && it2.hasNext()){
                Item tempItem1 = it1.next();
                Item tempItem2 = it2.next();
                compVal = tempItem1.compareTo(tempItem2);
            }
        }
        return compVal;
    }

	@Override
	public Iterator<Item> iterator() {
		return itemSet.iterator();
	}
}